home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1989 …il & Dave's Excellent CD / Excellent CD HFS.raw / Moof / Goodies / DTS Goodies / Hardware Hints / Examples / Example Vid ROM from C&D / C & D Ex Drvr.a next >
Encoding:
Text File  |  1988-05-24  |  14.1 KB  |  434 lines  |  [TEXT/MPS ]

  1. ;-----------------------------------------------------------------
  2.  
  3. ;General directives
  4.  
  5.             BLANKS        ON
  6.             STRING        ASIS
  7.  
  8.             
  9. ;=====================================================================
  10. ;    Local Vars, definitions, etc....
  11. ;=====================================================================
  12.  
  13. ; This is device storage which is stored in the dCtlStorage field of the DCE.
  14.  
  15. DCEPtr            EQU        0                        ; pointer to our DCE
  16. saveMode        EQU        DCEPtr+4                ; the current mode setting
  17. savePage        EQU        saveMode+2                ; the current page setting
  18. saveBaseAddr     EQU        savePage+2                ; the current base address
  19. saveSQElPtr     EQU        saveBaseAddr+4            ; the SQ element pointer (for _SIntRemove).
  20. GammaPtr         EQU        saveSQElPtr+4            ; the pointer to the Gamma correction table
  21. GFlags            EQU        GammaPtr+4                ; flags word
  22. VRAM256K        EQU        GFlags+2                ; boolean - TRUE if 256K vidRAM, FALSE if 512K
  23. dCtlSize        EQU        VRAM256K+2                ; size of dCtlStorage
  24.  
  25. ; Flags within GFlags word
  26.  
  27. GrayFlag        EQU        15                        ; luminance mapped if GFlags(GrayFlag) = 1
  28. TFB1K            EQU        0
  29.  
  30. ;=====================================================================
  31. ;    Video Driver Header
  32. ;=====================================================================
  33.             
  34. VidDrvr        DC.W    $4C00                    ; ctl,status,needsLock
  35.             DC.W    0,0,0                    ; not an ornament
  36.  
  37. ; Entry point offset table
  38.  
  39.             DC.W    VideoOpen-VidDrvr         ; open routine
  40.             DC.W    VidDrvr-VidDrvr            ; no prime
  41.             DC.W    VideoCtl-VidDrvr        ; control
  42.             DC.W    VideoStatus-VidDrvr        ; status
  43.             DC.W    VideoClose-VidDrvr        ; close
  44.  
  45.  
  46.             STRING        Pascal
  47. VideoTitle    DC.B        '.Display_Video_Apple_TFB'    ;
  48.             STRING        ASIS
  49.             ALIGN    2                        ; make sure we're aligned
  50.             DC.W    0                        ; version-0
  51.  
  52. **********************************************************************
  53. *
  54. * VideoOpen allocates private storage for the device in the DCE and locks
  55. *    it down for perpituity. Also, install the interrupt handler and enable
  56. *    the interrupts.                                                                                                                 <22Sep86>
  57. *   It also sets the default gamma table included in the driver                        
  58. *
  59. * Entry:    A0 = param block pointer
  60. *            A1 = DCE pointer
  61. *
  62. * Locals:    A2 = Saved param block pointer
  63. *            A3 = Saved DCE pointer
  64. *            A4 = Saved interrupt handler ptr.
  65. *
  66. **********************************************************************
  67.  
  68. ; Save registers
  69. VideoOpen    MOVE.L    A0,A2                        ;A2 <- param block pointer
  70.             MOVE.L    A1,A3                        ;A3 <- DCE pointer
  71.             
  72. ; Allocate private storage.
  73.             MOVEQ    #dCtlSize,D0                ; get size of parameters
  74.             _ResrvMem  ,SYS                     ; make room as low as possible
  75.             MOVEQ    #dCtlSize,D0                ; get size of parameters
  76.             _NewHandle ,SYS,CLEAR                ; get some memory for private storage
  77.             BNE      OpError                        ; => return an error in open
  78.             MOVE.L    A0,dCtlStorage(A3)            ; save returned handle in DCE
  79.             _HLock                                ; and lock it down
  80.             
  81. ; Get and install the interrupt handler.                                        
  82.             LEA        BeginIH,A4                    ;Save Pointer to interrupt handler.    
  83.             MOVEQ    #sqHDSize,D0                ;allocate a slot queue element
  84.             _NewPtr    ,SYS,CLEAR                    ;get it from system heap cleared
  85.             BNE      OpError
  86.             MOVE.W    #SIQType,SQType(A0)            ;setup queue ID                        
  87.             MOVE.L    A4,SQAddr(A0)                ;setup int routine address
  88.             MOVE.L    dctlDevBase(A3),SQParm(A0)    ;save slot base addr as A3 parm
  89.             CLR.L    D0
  90.             MOVE.B    dctlSlot(A3),D0                ;setup slot #
  91.             _SIntInstall                        ;and do install
  92.             BNE.S    OpError
  93.  
  94. ; Save SQElPtr for removal.                                                            
  95.             MOVE.L    dCtlStorage(A3),A1            ;Get pointer to private storage.
  96.             MOVE.L    (A1),A1                        ;    
  97.             MOVE.L    A0,saveSQElPtr(A1)            ;Save the SQ element pointer.
  98.  
  99. ; Enable interrupts..
  100.             ADD.L    #ClrVInt,A0                    ;bump to interrupt reg
  101.             CLR.B    (A0)                        ;clear it.
  102.  
  103.             MOVEQ    #0,D0                        ;no error
  104.             BRA.S    EndOpen
  105.  
  106. ;  Error.
  107. OpError        MOVE.L    #OpenErr,D0                    ; say can't open driver.
  108.  
  109.  
  110. EndOpen        RTS                                 ;return
  111.             
  112. ;-------------------------------------------------------------                                
  113. ;    The Interrupt handler for TFB board
  114. ;-------------------------------------------------------------
  115. ; The interrupt Handler
  116. ; On entry A1 contains the slot base address
  117. ; D0-D3/A0-A3 have been preserved.
  118. BeginIH        MOVE.L    A1,A0            ; get screen base
  119.             MOVE.L    A1,D0            ; and save for later
  120.             ADD.L    #ClrVInt,A0        ; get offset to register
  121.             CLR.B    (A0)            ; clear interrupt from card
  122.  
  123.                                     ; D0 = $Fssxxxxx
  124.             ROL.L    #8,D0            ; D0 <- $sxxxxxFs    Convert the address into 
  125.             AND        #$0F,D0            ; D0 <- $sxxx000s    the slot number.
  126.  
  127.             MOVE.L    JVBLTask,A0        ; call the VBL task manager
  128.             JSR        (A0)            ; with slot # in D0
  129.  
  130.             MOVEQ    #1,D0            ; signal that int was serviced                
  131.             RTS                        ; and return to caller
  132.  
  133.             
  134. **********************************************************************
  135. *
  136. * VideoClose releases the device's private storage.
  137. *
  138. *
  139. * Entry:    A0 = param block pointer
  140. *            A1 = DCE pointer
  141. *
  142. * Locals:    A2 = Saved param block pointer
  143. *            A3 = Saved DCE pointer
  144. *            A4 = Temporary.
  145. *
  146. **********************************************************************
  147.  
  148. VideoClose    
  149.             MOVE.L    A0,A2                        ;A2 <- param block pointer            
  150.             MOVE.L    A1,A3                        ;A3 <- DCE pointer                    
  151.  
  152.             MOVE.L    dCtlDevBase(A3),A4            ;A4 <- base address of device.        
  153.             ADD.L    #DisableVInt,A4                ;Adjust the base                    
  154.             CLR.B    (A4)                        ;Disable interrupt from card        
  155.  
  156.             MOVE.L    dCtlStorage(A3),A0            ;Get pointer to private storage        
  157.             MOVE.L    (A0),A0                        ;                                    
  158.             MOVE.L    saveSQElPtr(A0),A0            ;Get the SQ element pointer.        
  159.             _SIntRemove                            ;Remove the interrupt handler.        
  160.             
  161.             MOVE.L    dCtlStorage(A3),A0            ;Get pointer to private storage        
  162.             MOVE.L    (A0),A0                        ;                                    
  163.             MOVE.L    GammaPtr(A0),A0                ;get pointer to gamma table
  164.             _DisposPtr                            ;and dispose it
  165.             
  166.             MOVE.L    dCtlStorage(A3),A0            ;Dispose of the private storage.    
  167.             _DisposHandle                        ;                                
  168.  
  169.  
  170.             MOVEQ    #0,D0                        ;get error into D0        
  171.             RTS                                 ;return to caller
  172.  
  173.  
  174. **********************************************************************
  175. *
  176. * Video Driver Control Call Handler.  Right now there are six calls:
  177. *
  178. *    (0)  Reset (VAR mode, page: INTEGER; VAR BaseAddr: Ptr);
  179. *    (1)  KillIO
  180. *    (2)     SetMode(mode, page: INTEGER; VAR BaseAddr: Ptr);
  181. *
  182. *   Entry:     A0         = param block pointer
  183. *            A1         = DCE pointer
  184. *    Uses:    A2        = cs parameters (ie. A2 <- csParam(A0))  (must be preserved)
  185. *            A3         = scratch (doesn't need to be preserved)
  186. *            A4        = scratch (must be preserved)
  187. *            D0-D3     = scratch (don't need to be preserved)
  188. *
  189. *    Exit:    D0          = error code
  190. *
  191. **********************************************************************
  192.  
  193. ; Decode the call
  194. VideoCtl    MOVEM.L    A0/A4/D4,-(SP)                ; save work registers (A0 is saved because it is used by ExitDrvr).
  195.  
  196.             MOVE.W    csCode(A0),D0                ; get the opCode
  197.             MOVE.L    csParam(A0),A2                ; A2 <- Ptr to control parameters        
  198.  
  199.             CMP.W    #2,D0                        ;IF csCode NOT IN [0..6] THEN            
  200.             BHI.S    CtlBad                        ;  Error, csCode out of bounds.
  201.             LSL.W    #1,D0                        ;Adjust csCode to be an index into the table.
  202.             MOVE.W    CtlJumpTbl(PC,D0.W),D0        ;Get the relative offset to the routine.
  203.             JMP        CtlJumpTbl(PC,D0.W)            ;GOTO the proper routine.
  204.                 
  205. CtlJumpTbl    DC.W    VidReset-CtlJumpTbl            ;$00 => VidReset
  206.             DC.W    CtlGood-CtlJumpTbl            ;$01 => CtlGood
  207.             DC.W    SetVidMode-CtlJumpTbl        ;$02 => SetVidMode
  208.  
  209. CtlBad        MOVEQ    #controlErr,D0                ; else say we don't do this one
  210.             BRA.S    CtlDone                        ; and return
  211.             
  212. CtlGood        MOVEQ    #noErr,D0                    ; return no error
  213.  
  214. CtlDone        MOVEM.L    (SP)+,A0/A4/D4                ; restore registers.
  215.             BRA        ExitDrvr
  216.  
  217. VidReset
  218. ;---------------------------------------------------------------------
  219. ;
  220. ;    Reset the card to its default (one bit per pixel)
  221. ;
  222. ;---------------------------------------------------------------------
  223.  
  224.             BSR        TFBInit                        ; initialize the card            
  225.             MOVE    #OneBitMode,csMode(A2)        ; return default mode            
  226.             MOVE    #1,D1                        ; get depth in D1                
  227.             MOVEQ    #0,D0                        ; get page in D0                
  228.             MOVE    D0,csPage(A2)                ; return the page                
  229.             MOVE.L    dCtlStorage(A1),A3            ; get handle to our data        
  230.             MOVE.L    (A3),A3                        ; A3 = our data                    
  231.             BSR        TFBSetDepth                    ; set the depth    from D1            
  232.             BSR        TFBSetPage                    ; set the page from D0            
  233.             MOVE.L    saveBaseAddr(A3),csBaseAddr(A2)    ; return the base address    
  234.             BSR        GrayScreen                    ; paint the screen gray            
  235.             BRA.S    CtlGood                        ; => no error                    
  236.  
  237. SetVidMode
  238. ;---------------------------------------------------------------------
  239. ;
  240. ;    Set the card to the specified mode and page.  
  241. ;     If either is invalid, returns badMode error.
  242. ;
  243. ;   If the card is already set to the specified mode, then do nothing.
  244. ;
  245. ;    Note: Mode set is [1,2,4,8].
  246. ;
  247. ;---------------------------------------------------------------------
  248.  
  249.             MOVE.W    csMode(A2),D1                ; D1 = mode
  250.             BSR        ChkMode                        ; get mode, check, map to depth (1, 2, 4 or 8) {D1 <- depth}
  251.             BNE.S    CtlBad                        ; => not a valid mode
  252.             
  253.             MOVE.W    csPage(A2),D0                ; D0 = page
  254.             BSR        ChkPage                        ; check page                    
  255.             BNE.S    CtlBad                        ; => not a valid page            
  256.  
  257. ; Only set the mode if it has changed
  258. ; TFBSetDepth and TFBSetPage update the saved data in the dCtlStorage
  259.  
  260. SetEm        MOVE.L    dCtlStorage(A1),A3            ; get handle to our data
  261.             MOVE.L    (A3),A3                        ; A3 = our data
  262.             MOVE.W    csMode(A2),D2                ; D2 = mode                        
  263.             CMP        saveMode(A3),D2                ; has the mode changed?            
  264.             BEQ.S    ModeOK1                        ; => no, check the page            
  265.             BSR        TFBSetDepth                    ; set the depth, get rowbytes    
  266.             BSR        TFBSetPage                    ; set the page                    
  267.             BRA.S    NoChange                    ; => and return
  268.             
  269. ModeOK1        BSR        TFBSetPage                    ; set the page                    
  270.             
  271. NoChange    MOVE.L    saveBaseAddr(A3),csBaseAddr(A2)    ; return the base address    
  272.             BRA.S    CtlGood                        ; => return no error
  273.  
  274. **********************************************************************
  275. *
  276. * Video Driver Status Call Handler.  Right now there are three calls:
  277. *
  278. *    (0)  Error
  279. *    (1)  Error
  280. *    (2)     GetMode
  281. *    (3)  Error
  282. *    (4)     GetPage
  283. *    (5)     GetPageBase
  284. *
  285. *   Entry:     A0         = param block
  286. *            A1         = DCE pointer
  287. *    Uses:    A2        = cs parameters (ie. A2 <- csParam(A0))  (must be preserved)
  288. *            A3         = scratch (doesn't need to be preserved)
  289. *            D0-D3     = scratch (don't need to be preserved)
  290. *
  291. *    Exit:    D0          = error code
  292. *
  293. **********************************************************************
  294.  
  295. VideoStatus    MOVE.W    csCode(A0),D0                ; get the opCode
  296.             MOVE.L    csParam(A0),A2                ; A2 <- Ptr to control parameters    
  297.             
  298.  
  299.             CMP.W    #5,D0                        ;IF csCode NOT IN [0..6] THEN
  300.             BHI.S    StatBad                        ;  Error, csCode out of bounds.
  301.             LSL.W    #1,D0                        ;Adjust csCode to be an index into the table.
  302.             MOVE.W    StatJumpTbl(PC,D0.W),D0        ;Get the relative offset to the routine.
  303.             JMP        StatJumpTbl(PC,D0.W)        ;GOTO the proper routine.
  304.                 
  305. StatJumpTbl    DC.W    StatBad-StatJumpTbl            ;$00 => Error
  306.             DC.W    StatBad-StatJumpTbl            ;$01 => Error
  307.             DC.W    GetMode-StatJumpTbl            ;$02 => GetMode
  308.             DC.W    StatBad-StatJumpTbl            ;$03 => Error
  309.             DC.W    GetPage-StatJumpTbl            ;$04 => GetPage
  310.             DC.W    GetPageBase-StatJumpTbl        ;$05 => GetPageBase
  311.             
  312. StatBad        MOVEQ    #statusErr,D0                ; else say we don't do this one
  313.             BRA        ExitDrvr                    ; and return
  314.             
  315. StatGood    MOVEQ    #noErr,D0                    ; return no error
  316.             BRA        ExitDrvr
  317.  
  318.  
  319. GetMode
  320. ;---------------------------------------------------------------------
  321. ;
  322. ;    Return the current mode
  323. ;
  324. ;---------------------------------------------------------------------
  325.  
  326.             MOVE.L    dCtlStorage(A1),A3                ; get handle to our storage
  327.             MOVE.L    (A3),A3                            ; get pointer to our storage
  328.             MOVE.W    saveMode(A3),csMode(A2)            ; return the mode
  329.             MOVE.W    savePage(A3),csPage(A2)            ; return the page number
  330.             MOVE.L    saveBaseAddr(A3),csBaseAddr(A2)    ; and the base address
  331.             
  332.             BRA.S    StatGood                        ; => return no error
  333.             
  334.  
  335.             
  336. GetPage
  337. ;---------------------------------------------------------------------
  338. ;
  339. ;    Return the number of pages in the specified mode
  340. ;
  341. ;---------------------------------------------------------------------
  342.  
  343.             MOVE    csMode(A2),D1                ; get the mode                        
  344.             BSR        ChkMode                        ; check mode, get depth in D1        
  345.             BNE        StatBad                        ; => not a valid mode                
  346.  
  347.             MOVE.L    dCtlStorage(A1),A0            ; get private storage pointer    
  348.             TST.B    VRAM256K(A0)                ; 512K or 256K?                    
  349.             BNE.S    @1                            ; if TRUE, then 256K of RAM        
  350.             MOVEQ    #4,D0                        ; if FALSE, 512K vRAM (and 1 more page per mode)
  351.             BRA.S    @2
  352. @1            MOVEQ    #3,D0                        ; get one-bit page count            
  353. @2            DIVU    D1,D0                        ; divide by depth                    
  354.             ADD        #1,D0                        ; make it one based                    
  355.             MOVE    D0,csPage(A2)                ; return page count                    
  356.             BRA        StatGood                    ; => return no error                
  357.             
  358.             
  359.             
  360. GetPageBase
  361. ;---------------------------------------------------------------------
  362. ;
  363. ;    Return the base address for the specified page in the current mode
  364. ;
  365. ;---------------------------------------------------------------------
  366.             
  367.             MOVE.L    dCtlStorage(A1),A3            ; get handle to our storage            
  368.             MOVE.L    (A3),A3                        ; get pointer to our storage        
  369.             MOVE    saveMode(A3),D1                ; get the current mode                
  370.             BSR        ChkMode                        ; convert to depth in D1            
  371.             MOVE.W    csPage(A2),D0                ; get the requested page            
  372.             BSR        ChkPage                        ; is the page valid?                
  373.             BNE        StatBad                        ; => no, just return                
  374.                         
  375.             MOVE    saveMode(A3),D1                ; get the current mode                
  376.             SUB        #OneBitMode,D1                ; make it 0 based                    
  377.             LEA        ModeTbl,A0                    ; point to tables                    
  378.             MULU    4(A0,D1*8),D0                ; calc page * rowBytes                
  379.             MULU    6(A0,D1*8),D0                ; calc page * rowBytes * height        
  380.             MOVEQ    #4,D1                        ; add offset for TFB                
  381.             ADD.L    D1,D0                        ; which doesn't use first long        
  382.             ADD.L    dCtlDevBase(A1),D0            ; add base address for card            
  383.             MOVE.L    D0,csBaseAddr(A2)            ; return the base address            
  384.             
  385.             BRA     StatGood                    ; => return no error
  386.             
  387.  
  388. ;---------------------------------------------------------------------
  389. ;
  390. ;    Exit from control or Status.
  391. ;
  392. ;---------------------------------------------------------------------
  393.  
  394. ExitDrvr    BTST    #NoQueueBit,ioTrap(A0)        ; no queue bit set?
  395.             BEQ.S    GoIODone                    ; => no, not immediate
  396.             RTS                                 ; otherwise, it was an immediate call
  397.  
  398. GoIODone    MOVE.L    JIODone,A0                    ; get the IODone address
  399.             JMP     (A0)                        ; invoke it
  400.  
  401.  
  402.  
  403.  
  404. **********************************************************************
  405. *
  406. *    Utilities (Hardware dependent)
  407. *
  408. **********************************************************************
  409.  
  410. TFBInit        RTS                                    ;Initialize the TFB
  411.  
  412. TFBSetDepth    RTS                                    ;Set the depth.
  413.  
  414. TFBSetPage    RTS                                    ;Set the page.
  415.  
  416. ChkMode        RTS                                    ;Check the current mode.
  417.  
  418. ChkPage        RTS                                    ;Check the current page.
  419.  
  420. GrayScreen    RTS                                    ;Gray the screen.
  421.  
  422. ModeTbl        DC.W    $AAAA,$AAAA,$0080,$01E0        ; one bit per pixel                    
  423.             DC.W    $CCCC,$CCCC,$0100,$01E0        ; two bit per pixel                    
  424.             DC.W    $F0F0,$F0F0,$0200,$01E0        ; four bit per pixel                
  425.             DC.W    $FF00,$FF00,$0400,$01E0        ; eight bit per pixel                
  426.             
  427.